package com.graduation.dairy.controller;

import com.graduation.dairy.dto.UserRegistrationRequest;
import com.graduation.dairy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public ResponseEntity<String> register(@RequestBody UserRegistrationRequest request) {
        boolean registered = userService.register(request.getEmail(), request.getPassword());
        if (registered) {
            return new ResponseEntity<>("Registration successful", HttpStatus.OK);
        }
        return new ResponseEntity<>("Email already exists", HttpStatus.BAD_REQUEST);
    }

}
